import { defineStore } from "pinia";
import { computed, ref } from 'vue'

//定义store
//defineStore（仓库名称，（）=>{...}）
export const useCountStore = defineStore('counter',()=> {
    //声明数据 state - count
    const count = ref(100)
    //声明操作数据方法 action
    const addcount = () => { count.value++ }
    const subcount = () => { count.value-- }
    //声明基于数据派生的计算属性 getters
    const double = computed(() => count.value*2)
    //声明数据 state - msg
    const msg = ref({name1:'hello pinia'})
    const msg1 = ref({
        name: 'hello vuex',
        ...msg.value
    })
    return {
        count,
        addcount,
        subcount,
        double,
        msg,
        msg1
    }
})